<?php
class Tourism_goods_brand_model extends BZ_Model
{
    protected $table   = 'tourism_goods_brand';

    /*
     * 数据数量
     * */
    public function total($param = array())
    {
        $this->db->from($this->table.' as b');
        if(isset($param['brand_name']) && !empty($param['brand_name'])){
            $this->db->like('b.brand_name', trim($param['brand_name']));
        }
        if(isset($param['parent_id']) && $param['parent_id']!= 0 ){
            $this->db->where('b.category_id', (int)$param['parent_id']);
        }
        return $this->db->count_all_results();
    }

    /*
     * 数据列表
     * */
    public function page_list($page_num, $num, $param = array())
    {
        $this->db->from($this->table.' as b');
        if(isset($param['brand_name']) && !empty($param['brand_name'])){
            $this->db->like('b.brand_name', trim($param['brand_name']));
        }
        if(isset($param['parent_id']) && $param['parent_id']!= 0 ){
            $this->db->where('b.category_id', (int)$param['parent_id']);
        }
        $this->db->order_by('b.brand_id', 'ASC');
        $this->db->limit($page_num, $num);
        return $this->db->get();
    }

    /*
     *添加品牌
     * */
    public function addBrand($params)
    {
        $this->db->insert($this->table, $params);
        return $this->db->insert_id();
    }

    /*
     *根据category_Id 获取品牌信息
     * */
    public function getBrand($cid = 0)
    {
        $this->db->where('category_id',$cid);
        return $this->db->get($this->table);
    }

    /*
     *根据brand_Id 获取品牌信息
     * */
    public function getBrandByBrandId($bid)
    {
        $this->db->where('brand_id', $bid);
        return $this->db->get($this->table)->row();
    }
}